package com.neuedu.demoweb.web.framework;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.demoweb.utils.WebConstants;
import com.neuedu.demoweb.utils.WebUtil;
import com.neuedu.demoweb.web.controller.AdminController;
import com.neuedu.demoweb.web.controller.DefaultController;



/**
 * 这是中央控制器
 * 
 * @author chens
 *
 */
@WebServlet("/sys/*")
public class DispatcherServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String model = WebUtil.getModel(request);
		ServletController controller = null;

		switch (model) {
		case WebConstants.MODEL_ADMIN:
			controller = new AdminController();
			break;	
		default:
			// 模块名称错误，调用默认控制器进行错误处理
			controller = new DefaultController();
			break;
		}
		controller.doService(request, response);
	}

}
